## ---------------------------------------------------------------------- #
## Figure 5
## Christopher J. Fariss
## "Yes, Human Rights Practices Are Improving Over Time"
## American Political Science Review
## ---------------------------------------------------------------------- #
rm(list = ls())

par(mfrow=c(1,3), mar=c(2,3.5,2,.25))

library(gtools)

data_M_1 <- read.csv("M_1_Full_Data.csv")
data_M_ALL <- read.csv("M_All_Vary_Full_Data.csv")
data_M_2 <- read.csv("M_2_Full_Data.csv")

temp <- table(data_M_1$YEAR)
M_ALL_01 <- table(subset(data_M_ALL, theta_mean <= quantile(data_M_ALL$theta_mean,.01))$YEAR)
M_2_01 <- table(subset(data_M_2, theta_mean <= quantile(data_M_2$theta_mean,.01))$YEAR)
M_1_01 <- table(subset(data_M_1, theta_mean <= quantile(data_M_1$theta_mean,.01))$YEAR)

mat01 <- smartbind(temp, M_ALL_01, M_1_01, M_2_01)

par(mfrow=c(1,3), mar=c(7,3.5,2,.25))
barplot(t(mat01)[,2], space=0, ylim=c(0,11), yaxt="n", xaxt="n")
axis(side=1, at=c(1:length(1946:2015)), labels=rep("", length(1946:2015)))
axis(side=1, at=c(6,16,26,36,46,56,66), labels=c(1950,1960,1970,1980,1990,2000,2010))
axis(side=2, at=c(0,2,4,6,8,10), las=2, cex=1.25)
mtext(side=3, line=.25, "All Varying Standard", cex=1.25)
mtext(side=1, line=6, "Cingranelli and Fillippov\n(2018)", cex=1.25)
mtext(side=2, line=2, "Latent Variable Worst 1% of Country-Year Units", cex=1.25)
box()

barplot(t(mat01)[,3], space=0, ylim=c(0,11), yaxt="n",  xaxt="n")
axis(side=1, at=c(1:length(1946:2015)), labels=rep("", length(1946:2015)))
axis(side=1, at=c(6,16,26,36,46,56,66), labels=c(1950,1960,1970,1980,1990,2000,2010))
axis(side=2, at=c(0,2,4,6,8,10), las=2, cex=1.25)
mtext(side=3, line=.25, "Constant Standard", cex=1.25)
mtext(side=1, line=6, "Fariss\n(2014, 2019)", cex=1.25)
box()

barplot(t(mat01)[,4], space=0, ylim=c(0,11), yaxt="n",  xaxt="n")
axis(side=1, at=c(1:length(1946:2015)), labels=rep("", length(1946:2015)))
axis(side=1, at=c(6,16,26,36,46,56,66), labels=c(1950,1960,1970,1980,1990,2000,2010))
axis(side=2, at=c(0,2,4,6,8,10), las=2, cex=1.25)
mtext(side=3, line=.25, "Changing Standard", cex=1.25)
mtext(side=1, line=6 , "Fariss\n(2014, 2019)", cex=1.25)
box()

